/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * StartCheckpointDialog.java
 *
 * Created on Nov 30, 2009, 11:51:02 PM
 */

package ubadbtools.recoveryLogAnalyzer.gui.forms;

import java.awt.Frame;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import ubadbtools.recoveryLogAnalyzer.logRecords.RecoveryLogRecord;
import ubadbtools.recoveryLogAnalyzer.logRecords.StartCheckpointLogRecord;

public class StartCheckpointDialog extends javax.swing.JDialog {
    private RecoveryLogRecord logRecord = null;

    public static RecoveryLogRecord showDialog(Frame parent, Set<String> transactions)
    {
    	StartCheckpointDialog dialog = new StartCheckpointDialog(parent, true, transactions);
        dialog.setVisible(true);

        return dialog.logRecord;
    }

    /** Creates new form StartCheckpointDialog */
    public StartCheckpointDialog(java.awt.Frame parent, boolean modal,Set<String> transactions) {
        super(parent, modal);
        initComponents();

        lstTransacciones.setListData(transactions.toArray());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btnAceptar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        transaccionesActivas = new javax.swing.JScrollPane();
        lstTransacciones = new javax.swing.JList();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Start Checkpoint");
        getContentPane().setLayout(new java.awt.BorderLayout(5, 5));

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });
        jPanel1.add(btnAceptar);

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        jPanel1.add(btnCancelar);

        getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);

        jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 10, 0, 10));
        jPanel2.setLayout(new java.awt.BorderLayout());

        jLabel1.setText("Seleccione las transacciones activas:");
        jPanel2.add(jLabel1, java.awt.BorderLayout.NORTH);

        transaccionesActivas.setMaximumSize(new java.awt.Dimension(300, 32767));

        lstTransacciones.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        transaccionesActivas.setViewportView(lstTransacciones);

        jPanel2.add(transaccionesActivas, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        setVisible(false);
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        List<String> transactions = new ArrayList<String>();
        for (Object value : lstTransacciones.getSelectedValues()) {
            transactions.add(value.toString());
        }
        
        logRecord = new StartCheckpointLogRecord(transactions);
        setVisible(false);
    }//GEN-LAST:event_btnAceptarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JList lstTransacciones;
    private javax.swing.JScrollPane transaccionesActivas;
    // End of variables declaration//GEN-END:variables

}
